<!doctype html>
<html>
<head>
<title>Tests load() method of FontFace</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>
@font-face {
    font-family: Font1;
    src: url(../../resources/Ahem.ttf?font1);
}

@font-face {
    font-family: Font2;
    src: url(../../resources/DownLoadErrorAhem.otf);
}
</style>
<script>
function getDocumentFontFaces() {
    var faces = [];
    document.fonts.forEach(function(face) { faces.push(face); });
    return faces;
}

function rejection(promise) {
  return new Promise((resolve, reject) => promise.then(reject, resolve));
}

promise_test(async () => {
    face1 = getDocumentFontFaces()[0];
    assert_equals(face1.status, 'unloaded');
    face1.load();
    assert_equals(face1.status, 'loading');
    await face1.loaded;
    assert_equals(face1.status, 'loaded');
}, 'face1.load() should be fulfilled');

promise_test(async () => {
    face2 = getDocumentFontFaces()[1];
    assert_equals(face2.status, 'unloaded');
    face2.load();
    assert_equals(face2.status, 'loading');
    await rejection(face2.loaded);
    assert_equals(face2.status, 'error');
}, 'face2.load() should be rejected');

promise_test(async () => {
    face3 = new FontFace('Font3', 'url(../../resources/Ahem.ttf?font3)', {});
    assert_equals(face3.status, 'unloaded');
    face3.load();
    assert_equals(face3.status, 'loading');
    await face3.loaded;
    assert_equals(face3.status, 'loaded');
}, 'face3.load() should be fulfilled');

promise_test(async () => {
    face4 = new FontFace('Font4', 'url(../../resources/DownLoadErrorAhem.otf)', {});
    assert_equals(face4.status, 'unloaded');
    face4.load();
    assert_equals(face4.status, 'loading');
    await rejection(face4.loaded);
    assert_equals(face4.status, 'error');
}, 'face4.load() should be rejected');

promise_test(async () => {
    face5 = new FontFace('Font5', 'url(data:font/truetype;base64,), url(../../resources/Ahem.ttf?font5)', {});
    assert_equals(face5.status, 'unloaded');
    face5.load();
    assert_equals(face5.status, 'loading');
    await face5.loaded;
    assert_equals(face5.status, 'loaded');
}, 'face5.load() should be fulfilled');

</script>
</head>
<body>
</body>
</html>
